#!/usr/bin/env php
<?php

# A client that runs 10 'work' tasks at the same time.

function complete($task, $result)
{
  $result['data'] = $task->data();
  $result['handle'] = $task->jobHandle();
}

$begin = gettimeofday(true);

$client = new GearmanClient();
$client->addServer('127.0.0.1', 4730);

$results = array();
for ($x = 0; $x < 10; $x++)
  $client->addTask('work', "$x", &$results[$x]);

$client->setCompleteCallback("complete");
$client->runTasks();

printf("Jobs ran in %.6f seconds.\n",
       gettimeofday(true) - $begin);

for ($x = 0; $x < 10; $x++)
{
  print $results[$x]['handle'] . '=';
  print $results[$x]['data'] . "\n";
}

?>
